import 'dart:collection';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:opene/JhPickerTool.dart';
import 'package:opene/app_constant.dart';
import 'package:opene/app_theme.dart';
import 'package:opene/app_utils.dart';
import 'package:opene/base/base_state.dart';
import 'package:opene/base/loading.dart';
import 'package:opene/base/scan_code.dart';
import 'package:opene/home/authorize_bean.dart';
import 'package:opene/net/method/base_method.dart';
import 'package:opene/net/network_manager.dart';
import 'package:opene/net/response/base_response.dart';
import 'package:opene/ui/b2blabel/b2blabelmodel.dart';
import 'package:opene/ui/b2cpick/b2cpickcategoryscreen.dart';
import 'package:opene/ui/b2cpick/b2cpickmodel.dart';
import 'package:opene/ui/checkin/checkinmodel.dart';
import 'package:opene/ui/manage/adjust/adjustmodel.dart';
import 'package:opene/ui/tally/tallydialogscreen.dart';
import 'package:opene/ui/tally/tallymodel.dart';
import 'package:opene/ui/tally/tallyskuscreen.dart';
import 'package:opene/utils/ImageUtils.dart';
import 'package:toast/toast.dart';

class ReMeasureSubmitScreen extends StatelessWidget {
  Measure measure;

  ReMeasureSubmitScreen({this.measure});

  @override
  Widget build(BuildContext context) {
    return ReMeasureSubmitScreenPage(measure: measure);
  }
}

class ReMeasureSubmitScreenPage extends StatefulWidget {
  Measure measure;

  ReMeasureSubmitScreenPage({this.measure});

  @override
  _ReMeasureSubmitScreenPageState createState() => _ReMeasureSubmitScreenPageState(measure: measure);
}

class _ReMeasureSubmitScreenPageState extends BaseState<ReMeasureSubmitScreenPage> {
  Measure measure;

  final TextEditingController lengthEditingController = TextEditingController();
  final TextEditingController widthEditingController = TextEditingController();
  final TextEditingController heightEditingController = TextEditingController();
  final TextEditingController weightEditingController = TextEditingController();
  FocusNode lengthFocusNode = FocusNode();
  FocusNode widthFocusNode = FocusNode();
  FocusNode heightFocusNode = FocusNode();
  FocusNode weightFocusNode = FocusNode();

  _ReMeasureSubmitScreenPageState({this.measure});

  final TextEditingController dateController = TextEditingController();
  final controller = ScrollController();

  int index = 0, position;
  List<ChildPick> data = new List();

  String location = "";
  bool layoutLogisticsType = false;
  List<PhotoBean> lengthPhotos = new List();
  List<PhotoBean> widthPhotos = new List();
  List<PhotoBean> heightPhotos = new List();
  List<PhotoBean> weightPhotos = new List();

  @override
  String setTitle({String title}) {
    return !Utils.isEmpty(title) ? title : "Re-Measure: Submit";
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    lengthPhotos.add(new PhotoBean());
    widthPhotos.add(new PhotoBean());
    heightPhotos.add(new PhotoBean());
    weightPhotos.add(new PhotoBean());
    if (measure.measure == null) {
      measure.measure = "length,width,height,weight";
    }
    if (measure.locations != null || measure.locations.length > 0) {
      location = measure.locations[0];
    }
    lengthEditingController.text = Utils.getStringisDouble(measure.length);
    widthEditingController.text = Utils.getStringisDouble(measure.width);
    heightEditingController.text = Utils.getStringisDouble(measure.height);
    weightEditingController.text = Utils.getStringisDouble(measure.length);
    next = "Submit";
  }

  @override
  void dispose() {
    lengthFocusNode.dispose(); // 不要忘记销毁FocusNode
    widthFocusNode.dispose(); // 不要忘记销毁FocusNode
    heightFocusNode.dispose(); // 不要忘记销毁FocusNode
    weightFocusNode.dispose(); // 不要忘记销毁FocusNode
    super.dispose();
  }

  Future pickImages(context) async {
    File image = await ImageUtils.chosePhotoOnAlbumOrCamera(context: context);
    print(image.path);
    String name = "";
    setState(() {
      switch (index) {
        case 0:
          PhotoBean photoBean = new PhotoBean();
          photoBean.image = image;
          lengthPhotos.insert(position, photoBean);
          name = "length";
          break;
        case 1:
          PhotoBean photoBean = new PhotoBean();
          photoBean.image = image;
          widthPhotos.insert(position, photoBean);
          name = "width";
          break;
        case 2:
          PhotoBean photoBean = new PhotoBean();
          photoBean.image = image;
          heightPhotos.insert(position, photoBean);
          name = "height";
          break;
        case 3:
          PhotoBean photoBean = new PhotoBean();
          photoBean.image = image;
          weightPhotos.insert(position, photoBean);
          name = "weight";
          break;
        case 4:
      }
      fileUpload("ReMeasure", "ReMeasure", image, name, index, position, false, false);
      print("index:${index},position:${position}");
      print(image.path);
    });
  }

  @override
  Widget getViewBinding() {
    return Container(
      margin: EdgeInsets.only(left: 15, right: 15, top: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(
              top: 0,
            ),
            child: Row(
              children: [
                Text(
                  "SKU: ",
                  style: TextStyle(color: MyAppTheme.color_666666, fontSize: 14.0),
                ),
                Expanded(
                  child: Text(
                    Utils.getStringisEmpty(measure.sku),
                    style: TextStyle(color: MyAppTheme.color_333333, fontSize: 14.0),
                  ),
                ),
              ],
            ),
          ),
          Visibility(
            visible: measure.locations == null || measure.locations == 0 ? false : true,
            child: Row(
              children: [
                Text(
                  "Location: ",
                  style: TextStyle(color: MyAppTheme.color_666666, fontSize: 14.0),
                ),
                Expanded(
                  child: ElevatedButton(
                    child: Row(
                      children: [
                        Expanded(
                            child: Text(
                          Utils.getStringisEmpty(location),
                          style: TextStyle(
                            color: MyAppTheme.darkText,
                          ),
                        )),
                        Icon(
                          Icons.keyboard_arrow_down,
                          size: 20,
                          color: MyAppTheme.nearlyBlue,
                        ),
                      ],
                    ),
                    style: ButtonStyle(
                      textStyle: MaterialStateProperty.all(
                        Theme.of(context).textTheme.subtitle1,
                      ),
                      alignment: Alignment.centerLeft,
                      elevation: MaterialStateProperty.all(0),
                      backgroundColor: MaterialStateProperty.all<Color>(Colors.white),
                      shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                        RoundedRectangleBorder(
                          side: BorderSide(width: 1, color: MyAppTheme.nearlyBlue),
                          borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                        ),
                      ),
                    ),
                    onPressed: () {
                      // 请求焦点
                      FocusScope.of(context).requestFocus(FocusNode());
                      print("object");
                      if (measure.locations == null || measure.locations == 0) {
                        return;
                      }
                      print("2222222");
                      JhPickerTool.showStringPicker(context, data: measure.locations, clickCallBack: (int index, var str) {
                        print(index);
                        print(str);
                        location = measure.locations[index];
                      });
                    },
                  ),
                )
              ],
            ),
          ),
          SizedBox(
            height: 5,
          ),
          Row(
            children: [
              Expanded(
                flex: 1,
                child: setInputView("length:  ", "inch", lengthEditingController, lengthFocusNode),
              ),
              Expanded(
                flex: 1,
                child: setInputView("width:  ", "inch", widthEditingController, widthFocusNode),
              ),
            ],
          ),
          Row(
            children: [
              Expanded(
                flex: 1,
                child: setInputView("height:  ", "inch", heightEditingController, heightFocusNode),
              ),
              Expanded(
                flex: 1,
                child: setInputView("weight:  ", "lb", weightEditingController, weightFocusNode),
              ),
            ],
          ),
          Expanded(
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    Visibility(
                      visible: measure.measure.contains("length") ? true : false,
                      child: Container(
                        margin: const EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 0),
                        child: Column(
                          children: <Widget>[
                            Row(
                              children: [
                                Text(
                                  '*',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: MyAppTheme.red, fontSize: 12.0),
                                ),
                                Text(
                                  'length(s):',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: MyAppTheme.color_666666, fontSize: 12.0),
                                ),
                              ],
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            Container(
                              height: 70,
                              width: double.infinity,
                              child: setPhotoListView(0, lengthPhotos),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Visibility(
                      visible: measure.measure.contains("width") ? true : false,
                      child: Container(
                        margin: const EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 0),
                        child: Column(
                          children: <Widget>[
                            Row(
                              children: [
                                Text(
                                  '*',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: MyAppTheme.red, fontSize: 12.0),
                                ),
                                Text(
                                  'width(s):',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: MyAppTheme.color_666666, fontSize: 12.0),
                                ),
                              ],
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            Container(
                              height: 70,
                              width: double.infinity,
                              child: setPhotoListView(1, widthPhotos),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Visibility(
                      visible: measure.measure.contains("height") ? true : false,
                      child: Container(
                        margin: const EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 0),
                        child: Column(
                          children: <Widget>[
                            Row(
                              children: [
                                Text(
                                  '*',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: MyAppTheme.red, fontSize: 12.0),
                                ),
                                Text(
                                  'height(s):',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: MyAppTheme.color_666666, fontSize: 12.0),
                                ),
                              ],
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            Container(
                              height: 70,
                              width: double.infinity,
                              child: setPhotoListView(2, heightPhotos),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Visibility(
                      visible: measure.measure.contains("weight") ? true : false,
                      child: Container(
                        margin: const EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 0),
                        child: Column(
                          children: <Widget>[
                            Row(
                              children: [
                                Text(
                                  '*',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: MyAppTheme.red, fontSize: 12.0),
                                ),
                                Text(
                                  'weight(s):',
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: MyAppTheme.color_666666, fontSize: 12.0),
                                ),
                              ],
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            Container(
                              height: 70,
                              width: double.infinity,
                              child: setPhotoListView(3, weightPhotos),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ], // 生成一个长列表
                ),
              ),),
        ],
      ),
    );
  }

  Container setInputView(String hintText, String hint, TextEditingController editingController, FocusNode focusNode) {
    return Container(
      margin: const EdgeInsets.only(left: 0, top: 10, right: 0, bottom: 0),
      width: double.infinity,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Expanded(
            flex: 1, //设置权重
            child: Container(
              margin: EdgeInsets.only(top: 10),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Text(
                    hintText,
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(color: MyAppTheme.color_666666, fontSize: 12.0),
                  ),
                ],
              ),
            ),
          ),
          Expanded(
              flex: 2, //设置权重
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    width: 70,
                    child: ConstrainedBox(
                      constraints: BoxConstraints(maxHeight: 30),
                      child: TextField(
                        focusNode: focusNode,
                        keyboardType: TextInputType.number,
                        controller: editingController,
                        textInputAction: TextInputAction.next,
                        // autofocus: true,
                        decoration: InputDecoration(
                          border: OutlineInputBorder(
                            borderSide: BorderSide(
                              color: MyAppTheme.nearlyBlue,
                            ),
                            borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                          ),
                          enabledBorder: OutlineInputBorder(
                            borderSide: BorderSide(color: MyAppTheme.nearlyBlue),
                            // 设置焦点之外的边框颜色
                            borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                          ),
                          focusedBorder: OutlineInputBorder(
                            borderSide: BorderSide(color: MyAppTheme.nearlyBlue),
                            // 设置焦点时的边框颜色
                            borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                          ),
                          hintText: hint,
                          filled: true,
                          fillColor: MyAppTheme.white,
                          //隐藏下划线
                          //border: InputBorder.none,
                          hintStyle: const TextStyle(color: Colors.grey),
                          contentPadding: const EdgeInsets.symmetric(vertical: 0, horizontal: 15),
                        ),
                        onChanged: (text) {
                          if (!Utils.isDouble(text)) {
                            editingController.text = "";
                            return;
                          }
                        },
                      ),
                    ),
                  ),
                ],
              )),
        ],
      ),
    );
  }

  ListView setPhotoListView(int type, List<PhotoBean> data) {
    return ListView.builder(
      scrollDirection: Axis.horizontal,
      itemCount: data == null ? 0 : data.length,
      itemBuilder: (context, index) {
        PhotoBean photoBean = data[index];
        print(photoBean.toString());
        return Container(
          height: 70,
          width: 70,
          margin: const EdgeInsets.only(left: 0, top: 0, right: 10, bottom: 0),
          child: Stack(
            children: <Widget>[
              GestureDetector(
                onTap: () {
                  // 请求焦点
                  FocusScope.of(context).requestFocus(FocusNode());
                  this.index = type;
                  this.position = index;
                  ((photoBean.image == null) && Utils.isEmpty(photoBean.urlImg)) ? pickImages(context) : imgFileDialog(photoBean, Constants.baseImgUrl);
                },
                child: photoBean.image == null
                    ? (photoBean.urlImg == null
                        ? Image.asset(
                            'assets/images/add.png',
                            width: 70,
                            height: 70,
                            fit: BoxFit.cover,
                          )
                        : Image.network(
                            Constants.baseImgUrl + photoBean.urlImg,
                            width: 70,
                            height: 70,
                            fit: BoxFit.cover,
                          ))
                    : Image.file(
                        photoBean.image,
                        width: 70,
                        height: 70,
                        fit: BoxFit.cover,
                      ),
              ),
              Visibility(
                visible: ((photoBean.image == null) && Utils.isEmpty(photoBean.urlImg)) ? false : true,
                child: Positioned(
                  top: 2.0,
                  left: 53,
                  child: GestureDetector(
                    onTap: () {
                      setState(() {
                        data.removeAt(index);
                      });
                    },
                    child: Image.asset(
                      'assets/images/ic_delete_menu.png',
                      width: 15,
                      height: 15,
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  @override
  void setNext() {
    print("setNext");
    setSubmit();
  }

  bool judgeType(String mold, String hint) {
    if (Utils.isEmpty(mold)) {
      this.hint = hint;
      Toast.show(hint, duration: Toast.lengthShort, gravity: Toast.bottom);
      return false;
    }
    if (mold == null) {
      this.hint = hint;
      Toast.show(hint, duration: Toast.lengthShort, gravity: Toast.bottom);
      return false;
    }
    if (!Utils.isDouble(mold)) {
      this.hint = hint;
      Toast.show(hint, duration: Toast.lengthShort, gravity: Toast.bottom);
      return false;
    }
    if (double.parse(mold) <= 0) {
      this.hint = hint;
      Toast.show(hint, duration: Toast.lengthShort, gravity: Toast.bottom);
      return false;
    }
    return true;
  }

  @override
  void setReset() {
    setState(() {
      lengthEditingController.text = "";
      widthEditingController.text = "";
      heightEditingController.text = "";
      weightEditingController.text = "";
    });
  }

  @override
  void showFileUploadData(String path, int type, int position, bool isSubmit) {
    switch (type) {
      case 0:
        lengthPhotos[position].urlImg = path;
        break;
      case 1:
        widthPhotos[position].urlImg = path;
        break;
      case 2:
        heightPhotos[position].urlImg = path;
        break;
      case 3:
        weightPhotos[position].urlImg = path;
        break;
    }

    if (isSubmit) {
      setSubmit();
    }
  }

  void setSubmit() {
    ToastContext().init(context);
    String length = lengthEditingController.text;
    if (!judgeType(length, "Please enter the length")) {
      return;
    }
    String width = widthEditingController.text;
    if (!judgeType(width, "Please enter the width")) {
      return;
    }
    String height = heightEditingController.text;
    if (!judgeType(height, "Please enter the height")) {
      return;
    }
    String weight = weightEditingController.text;
    if (!judgeType(height, "Please enter the weight")) {
      return;
    }

    if (measure.measure.contains("length") && lengthPhotos.length == 1) {
      Toast.show("Please add length photos", duration: Toast.lengthShort, gravity: Toast.bottom);
      return;
    }
    if (measure.measure.contains("width") && widthPhotos.length == 1) {
      Toast.show("Please add width photos", duration: Toast.lengthShort, gravity: Toast.bottom);
      return;
    }
    if (measure.measure.contains("height") && heightPhotos.length == 1) {
      Toast.show("Please add height photos", duration: Toast.lengthShort, gravity: Toast.bottom);
      return;
    }
    if (measure.measure.contains("weight") && weightPhotos.length == 1) {
      Toast.show("Please add weight photos", duration: Toast.lengthShort, gravity: Toast.bottom);
      return;
    }

    if (DateTime.now().millisecondsSinceEpoch - timeMillis < 1000) {
      return;
    }
    timeMillis = DateTime.now().millisecondsSinceEpoch;

    List<String> lengthTemp = new List();
    for (int i = 0; i < lengthPhotos.length - 1; i++) {
      PhotoBean photoBean = lengthPhotos[i];
      if (Utils.isEmpty(photoBean.urlImg)) {
        position = i;
        fileUpload("ReMeasure", "ReMeasure", photoBean.image, "length", 0, position, true, true);
        return;
      }
      lengthTemp.add(photoBean.urlImg);
    }
    List<String> widthTemp = new List();
    for (int i = 0; i < widthPhotos.length - 1; i++) {
      PhotoBean photoBean = widthPhotos[i];
      if (Utils.isEmpty(photoBean.urlImg)) {
        position = i;
        fileUpload("ReMeasure", "ReMeasure", photoBean.image, "length", 1, position, true, true);
        return;
      }
      widthTemp.add(photoBean.urlImg);
    }

    List<String> heightTemp = new List();
    for (int i = 0; i < heightPhotos.length - 1; i++) {
      PhotoBean photoBean = heightPhotos[i];
      if (Utils.isEmpty(photoBean.urlImg)) {
        position = i;
        fileUpload("ReMeasure", "ReMeasure", photoBean.image, "height", 2, position, true, true);
        return;
      }
      heightTemp.add(photoBean.urlImg);
    }
    List<String> weightTemp = new List();
    for (int i = 0; i < weightPhotos.length - 1; i++) {
      PhotoBean photoBean = weightPhotos[i];
      if (Utils.isEmpty(photoBean.urlImg)) {
        position = i;
        fileUpload("ReMeasure", "ReMeasure", photoBean.image, "weight", 3, position, true, true);
        return;
      }
      weightTemp.add(photoBean.urlImg);
    }

    // measure.setLocation(binding.tvLocation.getText().toString());
    measure.length = double.parse(length);
    measure.width = double.parse(width);
    measure.height = double.parse(height);
    measure.weight = double.parse(weight);
    measure.lengthPaths = lengthTemp;
    measure.widthPaths = widthTemp;
    measure.heightPaths = heightTemp;
    measure.weightPaths = weightTemp;

    CheckSkuParam checkSkuParam = new CheckSkuParam();
    checkSkuParam.warehousingNotifyId = measure.notifyId;
    checkSkuParam.sku = (measure.sku);
    List<double> sizes = new List();
    sizes.add(measure.length);
    sizes.add(measure.width);
    sizes.add(measure.height);
    checkSkuParam.sizes = sizes;
    checkSkuParam.weight = measure.weight;
    checkSku(checkSkuParam);
  }

  void checkSku(CheckSkuParam checkSkuParam) async {
    try {
      // 显示加载中对话框
      LoadingIndicator.show(context, title: "Check...");
    } catch (e) {
      e.toString();
    }
    String json = jsonEncode(checkSkuParam);

    BaseResponse baseResponse = await NetworkManager().request(context, Constants.checkSkuParam, method: BaseMethod.post, data: json);

    try {
      // 在需要的时候隐藏加载中对话框
      LoadingIndicator.hide();
    } catch (e) {
      e.toString();
    }

    if (baseResponse.status == 200) {
      setState(() {
        CheckSkuParam checkSkuParamTemp = CheckSkuParam.fromJson(baseResponse.data);
        double weight = checkSkuParamTemp.weight;
        List<double> sizes = checkSkuParamTemp.sizes;
        bool isLength = false;
        bool isWidth = false;
        bool isHeight = false;
        bool isWeight = false;

        if (weight != null) {
          isWeight = true;
        }
        sizes.forEach((d) {
          if (d - measure.length == 0) {
            isLength = true;
          }
          if (d - measure.width == 0) {
            isWidth = true;
          }
          if (d - measure.height == 0) {
            isHeight = true;
          }
        });

        if ((!isLength) && (!isWidth) && (!isHeight) && (!isWeight)) {
          submitReMeasure();
          return;
        }

        SkuExceed skuExceed = new SkuExceed();
        skuExceed.smallItem = checkSkuParamTemp.smallItem;
        skuExceed.isLength = isLength;
        skuExceed.isWidth = isWidth;
        skuExceed.isHeight = isHeight;
        skuExceed.isWeight = isWeight;
        showDialog(
          context: context,
          builder: (context) => SkuExceedDialog(skuExceed: skuExceed),
        ).then((value) => {
              print("result2:${value}"),
              if ((value != null) && (value == "ok")) {submitReMeasure()}
            });
      });
    } else {
      ToastContext().init(context);
      Toast.show(Utils.getStringisEmpty(baseResponse.msg), duration: Toast.lengthShort, gravity: Toast.bottom);
    }
  }

  void submitReMeasure() async {
    try {
      // 显示加载中对话框
      LoadingIndicator.show(context, title: "Submit...");
    } catch (e) {
      e.toString();
    }
    String json = jsonEncode(measure);

    String url = Constants.reMeasure;
    int version = 0;
    try {
      if (Constants.jumpMapBean != null) {
        List<JumpBean> data = Constants.jumpMapBean.MANAGE_Adjustment.data;
        for (JumpBean jumpBean in data) {
          if (jumpBean.name == "ReMeasure") {
            version = jumpBean.version;
          }
        }
      }
    } catch (e) {
      e.printStackTrace();
    }
    if (version == 2) {
      url = Constants.reMeasure_v2_submit;
    }

    BaseResponse baseResponse = await NetworkManager().request(context, url, method: BaseMethod.put, data: json);

    try {
      // 在需要的时候隐藏加载中对话框
      LoadingIndicator.hide();
    } catch (e) {
      e.toString();
    }

    if (baseResponse.status == 200) {
      Navigator.of(context).pop(true);
    } else {
      ToastContext().init(context);
      Toast.show(Utils.getStringisEmpty(baseResponse.msg), duration: Toast.lengthShort, gravity: Toast.bottom);
    }
  }
}
